var zuocedaohuang = document.querySelectorAll("#zuocedaohuang>ul>li>div");

//物联设备
$("#bs-example-navbar-collapse-1 ul:nth-child(3) li:nth-child(2) a").click(function () {
    $("body").load("WuJiaHanWuLianSheBei.html");
})
//主页
$("#zuocedaohuang>ul>li:nth-child(1)").click(function () {
    $("body").load("index.html");
})
//修改密码
$("#zuocedaohuang>ul>li:nth-child(8)>ul>li:first-child").click(function () {
    $("body").load("yaoketongxiugaimm.html");
})
$(".dropdown-menu>li:first-child").click(function () {
    $("body").load("yaoketongxiugaimm.html");
})
//人员管理
$("#zuocedaohuang>ul>li:nth-child(2)>ul>li").click(function () {
    $("body").load("WuJiaHanRenYuanGuanLi.html");
})
//初始化
$("#zuocedaohuang>ul>li:nth-child(8)>ul>li:last-child").click(function () {
    $("body").load("chushihua.html");
})
//主页
$("#bs-example-navbar-collapse-1 ul:nth-child(3) li:nth-child(1) a").click(function () {
    $("body").load("index.html");
})

//物业管理
$("#zuocedaohuang>ul>li:nth-child(5)>ul>li:first-child").click(function () {
    $("body").load("HeLuYiJiaoFeiJiLu.html");
})
//订单管理
$("#zuocedaohuang>ul>li:nth-child(5)>ul>li:nth-child(2)").click(function () {
    $("body").load("HeLuYiDaiJiaoDingDan.html");
})
//收款账号
$("#zuocedaohuang>ul>li:nth-child(5)>ul>li:nth-child(3)").click(function () {
    $("body").load("HeLuYiShouKuanZhangHao.html");
})

//房源管理
$("#zuocedaohuang>ul>li:nth-child(3)>ul>li:first-child").click(function () {
    $("body").load("renchengdongfangyuanhuanli.html");
})
//房屋档案
$("#zuocedaohuang>ul>li:nth-child(3)>ul>li:nth-child(2)").click(function () {
    $("body").load("renchengdongfangwudangan.html");
})

//车位管理
$("#zuocedaohuang>ul>li:nth-child(4)>ul>li:first-child").click(function () {
    $("body").load("cx-chewguanli.html");
})
//车辆管理
$("#zuocedaohuang>ul>li:nth-child(4)>ul>li:nth-child(2)").click(function () {
    $("body").load("cx-chelguanli.html");
})

//工单配置
$("#zuocedaohuang>ul>li:nth-child(6)>ul>li:first-child").click(function () {
    $("body").load("第一个页面.html");
})
//报修管理
$("#zuocedaohuang>ul>li:nth-child(6)>ul>li:nth-child(2)").click(function () {
    $("body").load("第二个页面.html");
})
//物业信息
$("#zuocedaohuang>ul>li:nth-child(7)>ul>li:nth-child(3)").click(function () {
    $("body").load("YaoKeTongWuYeXingXi.html");
})
//信息服务
$("#zuocedaohuang>ul>li:nth-child(7)>ul>li:first-child").click(function () {
    $("body").load("LiuXueQiXinXiFuWu.html");
})
//账单配置
$("#zuocedaohuang>ul>li:nth-child(7)>ul>li:nth-child(2)").click(function () {
    $("body").load("LiuXueQiZhangDanPeiZhi.html");
})

$(".dropdown-toggle").click(function () {
    if (navpanding==1){
        $(".dropdown-menu").css("display","block");
        $(".dropdown-toggle").css("background-color","rgb(221,221,221)")
        navpanding=2;
    }else {
        $(".dropdown-menu").css("display","none");
        $(".dropdown-toggle").css("background-color","rgb(65,92,133)")
        navpanding=1;
    }
})







for(var i = 0 ;i<zuocedaohuang.length;i++){
    zuocedaohuang[i].onclick=function () {
        var liClick = this.parentNode;
        var haizi=liClick.querySelectorAll("ul>li");
        var liHeight = liClick.style.height;
        for(var n = 1 ;n<zuocedaohuang.length;n++){
            var fa=[];
            fa[n]= zuocedaohuang[n].parentNode;
            fa[n].style.height="50px";
            fa[n].style.transition="all 0.2s";
            zuocedaohuang[n].style.color="black";
            zuocedaohuang[n].querySelector("span").style.transform="rotatez(0deg)";
        }
        if(liHeight=="50px"){
            if(haizi&&haizi.length>0){
                this.style.color="black";
                liClick.style.height=50+haizi.length*50+"px";
                this.querySelector("span").style.transform="rotatez(180deg)";
                liClick.style.transition="all 0.2s";
            }
        }else {
            this.style.color="black";
            liClick.style.height="50px";
            this.querySelector("span").style.transform="rotatez(0deg)";
            liClick.style.transition="all 0.2s";
            this.querySelector("span").style.transform="rotatez(0deg)";
        }
    }
}
$(window).scroll(function () {
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    var i=scrollTop;
    if (scrollTop>500){
        $("#zuocedaohuang>ul").css("margin-top",scrollTop+"px");
    }
    if (scrollTop<500){
        $("#zuocedaohuang>ul").css("margin-top","0")
    }
})

var guanjiaxingming=$("#profile div:nth-child(1) input");
var zhuanyefenlei=$("#profile div:nth-child(2) input");
var lanxidianhua=$("#profile div:nth-child(3) input");
var fuzhequyu=$("#profile select");
var shanchuyemian=1;

//存放所有用户
var ykt = ykt || {};

//操作类型
var operateType = "";
//存放搜索对象
var searchUsers = searchUsers || {};

var User = {
    Create:function(XH,GJXM,LXDH,FZLC,FZQY,GXSJ,ZYFL,BXSJ,JDR,){
        this.xh = XH;
        this.gjxm = GJXM;
        this.lxdh = LXDH;
        this.fzlc = FZLC;
        this.fzqy = FZQY;
        this.gxsj = GXSJ;
        this.zyfl = ZYFL;
        this.bxsj = BXSJ;
        this.jdr = JDR;
    },
    //添加用户
    addUserData:function(){
        if(this.xh != ""){
            ykt[this.xh] = this;
        }
    },
}
function New(aClass,aParams){
    function new_(){
        aClass.Create.apply(this,aParams);
    }
    new_.prototype = aClass;
    return new new_();
}
//bootstrap模态框事件
$('#myModal').on('hide.bs.modal', function () {
    // 执行一些动作...
    var inputElements = this.getElementsByTagName("input");
    var userArr = [];
    for(var i=0;i<inputElements.length;i++){
        userArr[i] = inputElements[i].value;

        this.getElementsByTagName("input")[i].value="";
    }
    var user = New(User,userArr);
    //添加操作
    if(operateType == "add"){
        user.addUserData();
        refreshDatas(ykt);
        operateType="";
        yemashu();
        fanye1();
        shanchuyemian=1;
        yemaheshuj();
    }
});
function addRowData(datas){
    var tbodyElement = document.getElementById("tbody");
    var html = "";
    for(var i in datas){
        html = html +  "<tr><th>"
            + datas[i].xh +"</th><th>"
            + datas[i].gjxm +"</th><th>"
            + datas[i].lxdh +"</th><th>"
            + datas[i].fzlc +"</th><th>"
            + datas[i].fzqy+"</th><th>"
            + datas[i].gxsj +"</th><th>"
            + datas[i].zyfl+"</th><th>"
            + datas[i].bxsj+"</th><th>"
            + datas[i].jdr +"</th><th><button data-toggle=\"modal\" data-target=\"#myModal\" onclick='bianji(this)'>编辑</button> <button onclick='shanchu(this)'>删除</button></th></tr>";
    }
    tbodyElement.innerHTML = html;
}

function refreshDatas(datas){
    addRowData(datas);
}

function initUserDatas(){
    var initUser1 = New(User,["1","刘XX","15328686063","7栋","A区","2020-06-30  16:25:30","工程","20210627","陈仪"]);
    var initUser2 = New(User,["2","王XX","18783572726","1栋","A区","2020-06-30  16:25:30","保洁","20210627","何路意"]);
    var initUser3 = New(User,["3","尧XX","12387824894","2栋","B区","2020-06-30  16:25:30","保安","20210627","杜鸿伟"]);
    var initUser4 = New(User,["4","何XX","18928712732","1栋","B区","2020-06-30  16:25:30","园林","20210627","陈仪"]);
    var initUser5 = New(User,["5","杜XX","12412312223","3栋","C区","2020-06-30  16:25:30","工程","20210627","陈仪"]);
    var initUser6 = New(User,["6","幸XX","12434654636","4栋","A区","2020-06-30  16:25:30","保洁","20210627","陈仪"]);
    var initUser7 = New(User,["7","陈XX","16756878678","6栋","C区","2020-06-30  16:25:30","保安","20210627","金小明"]);
    var initUser8 = New(User,["8","蒋XX","43654375675","8栋","A区","2020-06-30  16:25:30","园林","20210627","王和冰"]);
    var initUser9 = New(User,["9","王XX","56746456546","6栋","C区","2020-06-30  16:25:30","工程","20210627","宋仕吉"]);
    var initUser10 = New(User,["10","宋XX","8547456456","5栋","A区","2020-06-30  16:25:30","保洁","20210627","陈仪"]);
    var initUser11 = New(User,["11","何XX","18782637827","3栋","B区","2020-06-30  16:25:30","园林","20210627","陈仪"]);
    var initUser12= New(User,["12","李XX","18998765431","1栋","C区","2020-06-30  16:25:30","保安","20210627","陈仪"]);
    var initUser13= New(User,["13","梁XX","19364838222","2栋","C区","2020-06-30  16:25:30","工程","20210627","何路易"]);
    var initUser14= New(User,["14","徐XX","19723647233","3栋","C区","2020-06-30  16:25:30","保安","20210627","杜鸿伟"]);
    var initUser15= New(User,["15","蒲XX","18726728723","2栋","B区","2020-06-30  16:25:30","保洁","20210627","陈仪"]);
    var initUser16= New(User,["16","吴XX","17678956411","7栋","C区","2020-06-30  16:25:30","园林","20210627","陈仪"]);
    var initUser17= New(User,["17","牛XX","17767234342","9栋","B区","2020-06-30  16:25:30","保安","20210627","杜鸿伟"]);
    var initUser18= New(User,["18","马XX","15328689798","10栋","D区","2020-06-30  16:25:30","园林","20210627","王和冰"]);
    var initUser19= New(User,["19","赖XX","18927398122","3栋","D区","2020-06-30  16:25:30","工程","20210627","何路易"]);
    var initUser20= New(User,["20","欧XX","12798247343","4栋","A区","2020-06-30  16:25:30","保安","20210627","何路易"]);
    ykt[initUser1.xh] = initUser1;
    ykt[initUser2.xh] = initUser2;
    ykt[initUser3.xh] = initUser3;
    ykt[initUser4.xh] = initUser4;
    ykt[initUser5.xh] = initUser5;
    ykt[initUser6.xh] = initUser6;
    ykt[initUser7.xh] = initUser7;
    ykt[initUser8.xh] = initUser8;
    ykt[initUser9.xh] = initUser9;
    ykt[initUser10.xh] = initUser10;
    ykt[initUser11.xh] = initUser11;
    ykt[initUser12.xh] = initUser12;
    ykt[initUser13.xh] = initUser13;
    ykt[initUser14.xh] = initUser14;
    ykt[initUser15.xh] = initUser15;
    ykt[initUser16.xh] = initUser16;
    ykt[initUser17.xh] = initUser17;
    ykt[initUser18.xh] = initUser18;
    ykt[initUser19.xh] = initUser19;
    ykt[initUser20.xh] = initUser20;
    return ykt;
}
/**
 * 首次加载页面执行方法
 */
// function loadUserDatas(){
    var userArray = initUserDatas();
    addRowData(userArray);
    refreshDatas(ykt);
    // fanye1();
    yemashu();
    fanye1();
// }
//用户操作
function add(param){
//获得操作类别
    document.getElementById("myModalLabel").innerText="添加用户";
    operateType = "add";

}

//删除
function shanchu(odj) {
    var i= parseInt($(odj).parent().parent().find("th")[0].innerText) ;
    delete ykt[i];
    $(odj).parent().parent().remove();
    yemashu();
    fanye2();

    yemaheshuj();
}

//编辑
function bianji(odj) {
    var i= parseInt($(odj).parent().parent().find("th")[0].innerText) ;
    var modal_body = document.getElementById("modal-body");
    var inputElements=  modal_body.getElementsByTagName("input");
    document.getElementById("myModalLabel").innerText="修改用户";
    inputElements[0].value=ykt[i].xh;
    inputElements[1].value=ykt[i].gjxm;
    inputElements[2].value=ykt[i].lxdh;
    inputElements[3].value=ykt[i].fzlc;
    inputElements[4].value=ykt[i].fzqy;
    inputElements[5].value=ykt[i].gxsj;
    inputElements[6].value=ykt[i].zyfl;
    inputElements[7].value=ykt[i].bxsj;
    inputElements[8].value=ykt[i].jdr;
    operateType = "add";
}


//管家查询
guanjiaxingming.blur(function () {
    if(guanjiaxingming.val()){
        for(var i in ykt){
            if(ykt[i].gjxm.indexOf(guanjiaxingming.val()) >= 0){
                searchUsers[ykt[i].xh] = ykt[i];
                refreshDatas(searchUsers);
            }
        }
    }
    searchUsers={};
    yemashu();
    fanye1();
    shanchuyemian=1;
    yemaheshuj();
})
// 专业分类查询
zhuanyefenlei.blur(function () {
    if(zhuanyefenlei.val()){
        for(var i in ykt){

            if(ykt[i].zyfl.indexOf(zhuanyefenlei.val()) >= 0){
                searchUsers[ykt[i].xh] = ykt[i];
                refreshDatas(searchUsers);
            }
        }
    }
    searchUsers={};
    yemashu();
    fanye1();
    shanchuyemian=1;
    yemaheshuj();
})
//联系电话查询
lanxidianhua.blur(function () {
    if(lanxidianhua.val()){
        for(var i in ykt){
            if(ykt[i].lxdh.indexOf(lanxidianhua.val()) >= 0){
                searchUsers[ykt[i].xh] =ykt[i];
                refreshDatas(searchUsers);
            }
        }
    }
    searchUsers={};
    yemashu();
    fanye1();
    shanchuyemian=1;
    yemaheshuj();
})
//工作状态查询
fuzhequyu.blur(function () {
    if(fuzhequyu.val()!="全部"){
        for(var i in ykt){
            if(ykt[i].fzqy.indexOf(fuzhequyu.val()) >= 0){
                searchUsers[ykt[i].xh] = ykt[i];
                refreshDatas(searchUsers);
            }
        }
    }else{
        for(var i in ykt){
            searchUsers[ykt[i].xh] = ykt[i];
            refreshDatas(searchUsers);
        }
    }
    searchUsers={};
    yemashu();
    fanye1();
    shanchuyemian=1;
    yemaheshuj();
})
//重置
// chongzhi.click(function () {
//     for(var i in users){
//         searchUsers[users[i].xh] = users[i];
//         refreshDatas(searchUsers);
//     }
//     yemashu();
//     fanye1();
//     shanchuyemian=1;
//     yemaheshuj();
// })
//页面数
function yemashu() {
    var yema=$(".section1 .yema");
    var neirong=$("#profile #tbody tr");
    var yema1=Math.ceil(neirong.length/8);
    var html="";
    if(yema1>0){
        for (var i=1;i<=yema1;i++){
            html=html+"<button onclick='fanye(this)'>"+i+"</button>";
        }
        yema[0].innerHTML=html;
        html="";
    }
}
//翻页
function fanye(odj) {
    var neirong=$("#profile #tbody tr");
    neirong.css("display","none");
    shanchuyemian=odj.innerText;
    for(var i=0;i<neirong.length;i++){
        if(i>=odj.innerText*8-8&&i<odj.innerText*8){
            neirong[i].style.display="table-row";
        }
    }
    yemaheshuj();
}
//加载翻页
function fanye1() {
    var neirong=$("#profile #tbody tr");
    neirong.css("display","none");
    for(var i=0;i<8;i++){
        if(i>=0&&i<8){
            neirong[i].style.display="table-row";
        }
    }
}
function fanye2(){
    var neirong=$("#profile #tbody tr");
    neirong.css("display","none");
    for(var i=0;i<neirong.length;i++){
        if(i>=shanchuyemian*8-8&&i<shanchuyemian*8){
            neirong[i].style.display="table-row";
        }
    }
}
function yemaheshuj() {
    var yemaheshujun=$(" .yemaheshujun");
    var neirong=$("#profile #tbody tr");
    yemaheshujun.text("当前页面："+shanchuyemian+" 一共"+neirong.length+"条数据")
}





